﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.DAL;
using Hr.DALContainer;
using Hr.IBLL;
using Hr.IDAL;
using Hr.Model;

namespace Hr.BLL
{
    public partial class RoleService : BaseService<Role_Name>, IRole_NameService
    {
        // 实现接口
        private IRole_NameDAL Role_NameDAL = Container.Resolve<IRole_NameDAL>();

        // 你的BLL层核心代码

        //引入Dal层
        protected RoleDAL Rdl = new RoleDAL();

        #region 获取数据方法块
        /// <summary>
        /// 根据角色ID，获取角色信息
        /// </summary>
        /// <param name="id">角色ID</param>
        /// <returns>角色信息</returns>
        /// <author>乐涛</author>
        /// <create>2020/8/7</create>
        /// <update>null</update>
        public Role_Name GetRoleName(int id)
        {
            return Rdl.GetRoleName(id);//调用Dal层的GetRoleName方法
        }

        /// <summary>
        /// 根据角色名称，进行模糊查询，返回集合
        /// </summary>
        /// <param name="RoleName_CHS"></param>
        /// <returns></returns>
        public List<Role_Name> SelRoleName(string RoleName_CHS)
        {
            return Rdl.SelRoleName(RoleName_CHS);
        }

        /// <summary>
        /// 获取角色所有信息，根据权限值排序
        /// </summary>
        /// <returns></returns>
        public List<Role_Name> GetRoleNameAll()
        {
            return Rdl.GetRoleNameAll();
        }

        /// <summary>
        /// 获取所有菜单信息,通过角色ID获取角色已开启权限菜单信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetMenuList(int fk_RoleName)
        {
            //return Rdl.GetMenuList(0);
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"MenuPage",Rdl.GetMenuList(0) },
                {"CheckDt",Rdl.GetRoleListCheck(fk_RoleName) }
            };
            return dt;
        }
        #endregion

        #region 删除角色
        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="pk_Name"></param>
        /// <returns></returns>

        public bool DelRoleName(int pk_Name)
        {
            Rdl.DelRoleName(Rdl.GetRoleName(pk_Name));
            return Rdl.SaveChanges();
        }

        #endregion


        #region 添加、修改
        /// <summary>
        /// 添加、修改角色信息
        /// </summary>
        /// <param name="r"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool UpdateRoleName(Role_Name r,string type)
        {
            Rdl.UpdateRoleName(r,type);
            return Rdl.SaveChanges();
        }

        /// <summary>
        /// 根据角色ID修改其绑定页面是否开启权限
        /// </summary>
        /// <param name="fk_RoleName"></param>
        /// <param name="CheckDt"></param>
        /// <returns></returns>
        public bool UpdateRoleCheck(int fk_RoleName,List<int> CheckDt)
        {
            Rdl.UpdateRoleCheck(fk_RoleName,CheckDt);
            return Rdl.Savechanges();
        }
        #endregion

        // 实现抽象类
        public override void SetDal()
        {
            Dal = Role_NameDAL;
        }
    }
}
